package com.example.ad

import android.os.Bundle
import android.view.View
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.ad.sdk.AdSdk
import com.example.ad.sdk.domain.ad.AdNative
import com.example.ad.sdk.domain.ad.AdSlot
import com.example.ad.sdk.domain.models.AdType
import com.example.ad.ui.theme.AdDemoTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            AdDemoTheme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    Greeting(
                        name = "Android",
                        modifier = Modifier.padding(innerPadding)
                    )
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    val context = LocalContext.current
    Column(
        modifier = modifier.fillMaxSize(),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.spacedBy(10.dp)
    ) {
        Text(
            text = "Hello $name!",
        )
        // 激励广告
        Button(
            onClick = {
                AdSdk.getAdManager().createNativeAd(context, AdSlot.Builder
                    .setChannel("001")
                    .setAdType(
                    AdType.TYPE_REWARD_VIDEO)
                    .build())
                    .loadInterstitialAd(object : AdNative.AdInteractionListener{
                    override fun onLoading() {
                        TODO("Not yet implemented")
                    }

                    override fun onLoaded(adView: View) {
                        TODO("Not yet implemented")
                    }

                    override fun onFailed(error: String) {
                        TODO("Not yet implemented")
                    }

                })
            }
        ) {
            Text("InterstitialAd")
        }
        //开屏广告
        Button(
            onClick = {
                AdSdk.getAdManager().createNativeAd(context, AdSlot.Builder
                    .setChannel("001")
                    .setAdType(
                        AdType.TYPE_SPLASH)
                    .build())
                    .loadSplashAd(object : AdNative.AdSplashListener{
                        override fun onLoading() {
                            TODO("Not yet implemented")
                        }

                        override fun onLoaded() {
                            TODO("Not yet implemented")
                        }

                        override fun onShowed() {
                            TODO("Not yet implemented")
                        }

                        override fun onFailed(error: String) {
                            TODO("Not yet implemented")
                        }

                    })
            }
        ) {
            Text("AdSplash")
        }
    }
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    AdDemoTheme {
        Greeting("Android")
    }
}